<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <form action="/upload" method="POST" enctype="multipart/form-data">
    <input type="file" id="file" name="img">
    <img src="" id="img" alt="">
    <button type="submit">上传文件</button>
  </form>
  <script>
    var file = document.getElementById('file');
    var img = document.getElementById('img');
    file.onchange = function(){
      var file = this.files[0];
      // new一个FileReader
      var fd = new FileReader();
      fd.readAsDataURL(file);
      fd.onload = function(){
        img.src = this.result;
      }
    }
  </script>
</body>
</html>